package com.babyqiao.wallpaper.portal.controller;

import com.babyqiao.wallpaper.common.UnifyResult;
import com.babyqiao.wallpaper.portal.entity.WallpaperAlbumPic;
import com.babyqiao.wallpaper.portal.entity.vo.AlbumResVO;
import com.babyqiao.wallpaper.portal.entity.vo.AlbumStatisVO;
import com.babyqiao.wallpaper.portal.service.IWallpaperAlbumService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author QLZ
 * @date 2021/2/25
 */
@RestController
@Api(tags = "专辑接口")
@RequestMapping("/wp/album")
public class PortalAlbumController {
    @Autowired
    IWallpaperAlbumService albumService;


    @GetMapping("albums/{current}/{limit}/{tagId}")
    @ApiOperation(value = "根据标签id获分页取专辑列表",httpMethod = "GET")
    public UnifyResult findAlbumByTagId(@ApiParam(name = "tagId",value = "标签id",required = true) @PathVariable String tagId,
                                        @ApiParam(name = "current",value = "当前页",required = true) @PathVariable long current,
                                        @ApiParam(name = "limit",value = "每页查询条数",required = true)@PathVariable long limit){
        //Page<AlbumResVO> page = new Page<>(current, limit);


        List<AlbumResVO> AlbumResVOs= albumService.findAlbumByTagId(current,limit,tagId);
        //long total = queryWrapper.getTotal();
        //数据的list
        //List<AlbumResVO> pageRecords = queryWrapper.getRecords();

        return UnifyResult.success().data("result", AlbumResVOs);

    }
    @GetMapping("albums/{current}/{limit}/{actorId}/actor")
    @ApiOperation(value = "根据演员id获取分页所有专辑",httpMethod = "GET")
    public UnifyResult getActorById(@ApiParam(name = "actorId",value = "演员ID",required = true) @PathVariable String actorId,
                                    @ApiParam(name = "current",value = "当前页",required = true) @PathVariable long current,
                                    @ApiParam(name = "limit",value = "每页查询条数",required = true)@PathVariable long limit){
        //Page<AlbumResVO> page = new Page<>(current, limit);
        List<AlbumResVO> albumResVOS=albumService.findAlbumByActor(current,limit,actorId);
        return UnifyResult.success().data("result",albumResVOS);
    }


    @GetMapping("album/{albumId}")
    @ApiOperation(value = "根据专辑id获取专辑图片",httpMethod = "GET")
    public UnifyResult findPicByAlbumId(@ApiParam(name = "albumId",value = "专辑id",required = true)@PathVariable String albumId){
        List<WallpaperAlbumPic>wallpaperAlbumPicList =albumService.findPicByAlbumIdService(albumId);
        return UnifyResult.success().data("result",wallpaperAlbumPicList);
    }

    @GetMapping("album/statis/{albumId}")
    @ApiOperation(value = "根据专辑id获取专辑活跃数据",httpMethod = "GET")
    public UnifyResult findStatisByAlbumId(@PathVariable String albumId){
        System.out.println("调用了statis");
        AlbumStatisVO albumStatisVO=albumService.findStatisByAlbumService(albumId);
        return UnifyResult.success().data("result",albumStatisVO);
    }



    /**
     * 点赞/取消点赞，对于表中like_it字段，前端人气排序根据他来排序
     * 规则：每个用户只能点赞一次，点赞完再点一次即为取消点赞
     * 逻辑：利用redis的bitmap实现，定期将点赞数据落地到mysql
     *
     * */

    @PostMapping("like/{albumId}/{userId}/{value}")
    @ApiOperation(value = "点赞/取消点赞",httpMethod = "POST")
    public UnifyResult likeIt(@ApiParam(name = "albumId",value = "专辑ID",required = true) @PathVariable String albumId,
                              @ApiParam(name = "userId",value = "用户ID",required = true) @PathVariable String userId,
                              @ApiParam(name = "value",value = "1->点赞，其他值->取消点赞",required = true) @PathVariable String value){
        boolean b=albumService.likeItService(albumId,userId,value);
        return UnifyResult.success();
    }

    @GetMapping("likestatus/{albumId}/{userId}")
    @ApiOperation(value = "获取点赞状态",httpMethod = "GET")
    public UnifyResult getLikeItStatus(@ApiParam(name = "albumId",value = "专辑ID",required = true) @PathVariable String albumId,
                                       @ApiParam(name = "userId",value = "用户ID",required = true) @PathVariable String userId){
        Boolean status=albumService.getLikeItStatusService(albumId,userId);
        return UnifyResult.success().data("result",status);

    }

    @GetMapping("likes/{albumId}")
    @ApiOperation(value = "获取点赞总数",httpMethod = "GET")
    public UnifyResult getLikeCount(@ApiParam(name = "albumId",value = "专辑ID",required = true) @PathVariable String albumId){
        System.out.println(albumId);
        Long count=albumService.getLikeCountService(albumId);
        return UnifyResult.success().data("result",count);
    }



}
